package com.jlcindia.struts2;

import java.util.Date;

import org.apache.struts2.config.*;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.validator.annotations.CustomValidator;
import com.opensymphony.xwork2.validator.annotations.DateRangeFieldValidator;
import com.opensymphony.xwork2.validator.annotations.DoubleRangeFieldValidator;
import com.opensymphony.xwork2.validator.annotations.EmailValidator;
import com.opensymphony.xwork2.validator.annotations.IntRangeFieldValidator;
import com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator;
import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
import com.opensymphony.xwork2.validator.annotations.StringLengthFieldValidator;
import com.opensymphony.xwork2.validator.annotations.UrlValidator;
import com.opensymphony.xwork2.validator.annotations.Validation;
@Results({
	@Result(name="success",value="/home.jsp"),
	@Result(name="input",value="/annoValidationTest.jsp"),
	@Result(name="failed",value="/annoValidationTest.jsp")
})
@Validation
public class AnnotatedTest extends ActionSupport {
	private String username;
	private String password;
	private int age;
	private double fee;
	private Date dob;
	private String email;
	private String web;
	
	public String execute()throws Exception{
		return "success";
	}
	
@RequiredStringValidator(message="Username is required")
@StringLengthFieldValidator(message="UserName must contain minimum of ${minLength}to maximum of${maxLength} characters",trim=true,minLength="6",maxLength="9")
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}
@RequiredStringValidator(message="Password is required")
@StringLengthFieldValidator(message="Password must contain minimum of ${minLength}to maximum of${maxLength} characters",trim=true,minLength="6",maxLength="9")
@CustomValidator(type="passwordstrategy",fieldName="password",message="Your Password must contain ane letter,one number and one of the following specialCharacters-$!@#?")	
public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@RequiredFieldValidator(message="Age is Required")
	@IntRangeFieldValidator(message="Age must be between $(min) and ${max}", min="18",max="25")
	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}
 
	@RequiredFieldValidator(message="Fee is required")
	@DoubleRangeFieldValidator(message="fee must be between ${minExclusive} and ${maxExclusive}",minExclusive="900.50",maxExclusive="999.50")
	public double getFee() {
		return fee;
	}

	public void setFee(double fee) {
		this.fee = fee;
	}

	@RequiredFieldValidator(message="DOB is Required")
	@DateRangeFieldValidator(message="DOB must be between ${min}and ${max}",min="01/01/2001",max="01/01/2012")
	public Date getDob() {
		return dob;
	}

	public void setDob(Date dob) {
		this.dob = dob;
	}

	@RequiredStringValidator(message="Email is Required")
	@EmailValidator(message="Email is invalid")
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@RequiredStringValidator(message="WebSite is required")
	@UrlValidator(message="url is invalid")
	public String getWeb() {
		return web;
	}

	public void setWeb(String web) {
		this.web = web;
	}
	

}
